package com.jingdianjichi.subject.domain.handler.subject;

import com.jingdianjichi.subject.common.enums.IsDeleteFlagEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTypeEnum;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBO;
import com.jingdianjichi.subject.domain.handler.SubjectTypeHandler;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class BriefTypeHandler implements SubjectTypeHandler {

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {

        SubjectBrief subjectBrief = new SubjectBrief();
        String subjectAnswerBO = subjectInfoBO.getSubjectAnswers();
//        SubjectBrief convertBrief = BriefSubjectConvert.INSTANCE.convert(subjectAnswerBo);
        subjectBrief.setSubjectAnswer(subjectAnswerBO);
        subjectBrief.setIsDelete(IsDeleteFlagEnum.UN_DELETED.getCode());
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Integer subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectId);
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBO optionBo = new SubjectOptionBO();
        optionBo.setSubjectAnswer(result.getSubjectAnswer());
        return optionBo;
    }
}
